package cn.digiwin.wx.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公众号（服务号）所用
 * <p>
 * Created by wenchuan on 2018/5/16.
 */
@RestController
@RequestMapping("wx/auth/gzh")
public class GzhAuthController {

    private static Logger logger = LoggerFactory.getLogger(GzhAuthController.class);

    //服务号Token, 需要与微信平台上设置的一致
    private static final String token = "wxtoken201805";


    /*
        获取公众号jsdk认证 参数
     */
//    @RequestMapping(value = {"jssdk"})
//    @ResponseBody
//    public Dto setJSSDKParamsCfg(HttpServletRequest request, HttpServletResponse response) {
//
//        //涉及调用 微信JS-SDK功能 获取临时认证票据
//        long timestamp = System.currentTimeMillis() / 1000;
//        String noncestr = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
//        String ticket = TicketUtil.getJsTicketGzh();
//        String fullurl = request.getParameter("url");
//        logger.debug("fullurl" + fullurl + "    noncestr" + noncestr + "    ticket" + ticket);
//
//        String tmpStr = "jsapi_ticket=" + ticket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + fullurl;
//        String signature = SecurityUtil.sHA1Encode(tmpStr).toLowerCase();
//        Dto outDto = Dtos.newOutDto();
//        outDto.put("signature", signature);
//        outDto.put("timestamp", timestamp);
//        outDto.put("noncestr", noncestr);
//        outDto.put("appId", AppCfgHandler.getValue("wx.gzh.appid"));
//        return outDto;
//    }

    /*
        公众号token认证

        用于Api操作公众号后台
     */
//    @RequestMapping(value = {"checkToken"})
//    @ResponseBody
//    public String checkToken(HttpServletRequest request, HttpServletResponse response) {
//        String echostr=null;
//        try {
//            Dto inDto = Dtos.newInDto(request);
//            String signature = inDto.getString("signature"); //微信加密签名
//            String timestamp = inDto.getString("timestamp"); //时间戳
//            String nonce = inDto.getString("nonce"); //随机数
//
//            ArrayList<String> list = new ArrayList<>();
//            list.add(nonce);
//            list.add(timestamp);
//            list.add(token);
//
//            //字典序排序
//            Collections.sort(list);
//            //SHA1加密
//            String checksignature = SecurityUtil.sHA1Encode(list.get(0) + list.get(1) + list.get(2)).toLowerCase();
//
//            if (checksignature.equals(signature)) {
//                echostr = inDto.getString("echostr"); //随机字符串
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return echostr;
//    }


}
